<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="../vue.js"></script>
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      姓：<input type="text" v-model="firstName" /> <br />
      名：<input type="text" v-model="lastName" /> <br />
      全名: <span>{{demo}}</span>
      <button @click="change">我姓名变化了</button>
    </div>
    <script>
      var app = new Vue({
        el: "#app",
        data: {
          firstName: "老",
          lastName: "六",
        },
        computed: {
          demo: {
            get() {
              return this.firstName + "-" + this.lastName;
            },
            set(value) {
              const arr = value.split("-");
              this.firstName = arr[0];
              this.lastName = arr[1];
            },
          },
        },
        methods: {
          change() {
            this.demo = "大-佬";
          },
        },
      });
    </script>
  </body>
</html>
